function decideOnSubmit(error) {
    if (error != ""  && error != null) {
        //var browser = navigator.appName;
        //if (browser == "Microsoft Internet Explorer") {
             //document.all["errorMessage"].innerHTML = error;
        //}
        //else 
         //   if (browser == "Netscape") {
                //document.getElementById("errorMessage").innerHTML = error;
				
         //   }   
			
		document.getElementById("errMessage").value = error;
		window.scrollTo(0,0);  
		return false;  
    }
    else {
        return true;
    }	
}


var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;
 
function pad(str, len, pad, dir) {
	if (typeof(len) == "undefined") { var len = 0; }
	if (typeof(pad) == "undefined") { var pad = ' '; }
	if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; } 
	if (len + 1 >= str.length) {
		switch (dir){
			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
			break; 
			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;
			default:
				str = str + Array(len + 1 - str.length).join(pad);
			break;
		} // switch
	}
	return str;
}

function padLabel(str) { 
	str = pad(str, 20, " ", STR_PAD_LEFT);

	return str;
}

function hideOrderMenus() {
	document.getElementById("manageOrders").style.display="block";
	document.getElementById("manageOrdersFoldout").style.display="none";		
}

function showOrderMenus() {
	document.getElementById("manageOrders").style.display="none";
	document.getElementById("manageOrdersFoldout").style.display="block";	
}



function hideEmployeeMenus() {
	document.getElementById("manageEmployees").style.display="block";
	document.getElementById("manageEmployeesFoldout").style.display="none";		
}

function showEmployeeMenus() {
	document.getElementById("manageEmployees").style.display="none";
	document.getElementById("manageEmployeesFoldout").style.display="block";	
}


function hideFabricMenus() {
	document.getElementById("manageFabrics").style.display="block";
	document.getElementById("manageFabricsFoldout").style.display="none";		
}

function showFabricMenus() {
	document.getElementById("manageFabrics").style.display="none";
	document.getElementById("manageFabricsFoldout").style.display="block";	
}



function hideGarmentMenus() {
	document.getElementById("manageGarments").style.display="block";
	document.getElementById("manageGarmentsFoldout").style.display="none";		
}

function showGarmentMenus() {
	document.getElementById("manageGarments").style.display="none";
	document.getElementById("manageGarmentsFoldout").style.display="block";	
}


function hideHolidayMenus() {
	document.getElementById("manageHolidays").style.display="block";
	document.getElementById("manageHolidaysFoldout").style.display="none";		
}

function showHolidayMenus() {
	document.getElementById("manageHolidays").style.display="none";
	document.getElementById("manageHolidaysFoldout").style.display="block";	
}

function  showErrorMessageDiv() {
	errText = document.getElementById('errMessage').value;
	if (errText != null && errText != "") {
		document.getElementById('errorMessage').innerHTML = errText;
		document.getElementById('errorMessage').style.display = "block";
	}
}

function  hideErrorMessageDiv() {
	document.getElementById('errMessage').value = "";
	document.getElementById('errorMessage').innerHTML = "";
	document.getElementById('errorMessage').style.display = "none";
}

//sets the content of the prompt div (at the bottom of the page) 
//according to the currently selected input
//all html element names of interest should be added in here
//the prompt would function as help for employees using the admin interface
function setPrompt(event) {
	
	event = event || window.event || {};
	var activeElement = event.srcElement || event.target;

	var promptText = "&nbsp;";
 	 
	switch (activeElement.id) {
		case 'e_hours_per_day':
		
			promptText = "Number of contractual work hours per workday.";
		 
			break;
		default: break;
	}
	document.getElementById("prompt").innerHTML = "&nbsp;&nbsp;&nbsp;" + promptText;
	
}


function clearPrompt(event) {
	document.getElementById("prompt").innerHTML = "&nbsp;";
}

//iterates over html inputs and dynamically adds the onprompt and onblur
//javascript event handlers
function setPromptHandlers(){	 
	inputs = document.getElementsByTagName('input');
	n = inputs.length;
	 
	while (n--) {
		
		inputs[n].onfocus = setPrompt;  
		inputs[n].onblur = clearPrompt;
	}
	
	inputs = document.getElementsByTagName('select');
	n = inputs.length;
	 
	while (n--) {
		inputs[n].onfocus = setPrompt;  
		inputs[n].onblur = clearPrompt;
	}	
}

function trim(str){
    str = str.replace(/\s+$/, '');
    str = str.replace(/^\s+/, '');
    return str;
}

function isValidPriceOrMeasurement(no){
    var isNumber = true;
    if (!no.match(/^[ ]*\d+(.\d\d?)?[ ]*$/)) {
        isNumber = false;
    }
    else {
        isNumber = true;
    }
    return isNumber;
}

function isValidNumber(no){
    var isNumber = true;
    if (!no.match(/^[ ]*\d+[ ]*$/)) {
        isNumber = false;
    }
    else {
        isNumber = true;
    }
    return isNumber;
}